#include "getgeometry.h"

GetGeometry::GetGeometry()
{

}
GetGeometry::~GetGeometry(){
}


int GetGeometry::Get_Point(double &X, double &Y, double &Z) {
    OGRPoint *poPoint = dynamic_cast<OGRPoint*>(poGeometry);
    X = poPoint->getX();
    Y = poPoint->getY();
    Z = poPoint->getZ();
    return 0;
}

int GetGeometry::Get_LineString(QVector<double> &vecX, QVector<double> &vecY, QVector<double> &vecZ){
    OGRLineString* pLineGeo = dynamic_cast<OGRLineString*>(poGeometry);
    int pointnums = pLineGeo->getNumPoints();
    for (int i = 0; i < pointnums; i++)
    {
        vecX.append(pLineGeo->getX(i));
        vecY.append(pLineGeo->getY(i));
        vecZ.append(pLineGeo->getZ(i));
    }
    return 0;
}

int GetGeometry::Get_Polygon(QMap<QString, QVector<double>> &coordinates, QMap<int, QMap<QString, QVector<double>>> &innerring){
    OGRPolygon *poPolygon = dynamic_cast<OGRPolygon *>(poGeometry);
    OGRPoint point;
    //外环
    OGRLinearRing *pOGRLinearRing = poPolygon->getExteriorRing();
    for (int i = 0; i < pOGRLinearRing->getNumPoints(); i++)
    {
        coordinates["X"].append(pOGRLinearRing->getX(i));
        coordinates["Y"].append(pOGRLinearRing->getY(i));
        coordinates["Z"].append(pOGRLinearRing->getZ(i));
    }
    //内环
    int innernums = poPolygon->getNumInteriorRings();
    if (innernums > 0)
    {
        for (int i = 0; i < innernums; i++)
        {
            pOGRLinearRing = poPolygon->getInteriorRing(i);
            for (int j = 0; j < pOGRLinearRing->getNumPoints(); j++)
            {
                innerring[i]["X"].append(pOGRLinearRing->getX(j));
                innerring[i]["Y"].append(pOGRLinearRing->getY(j));
                innerring[i]["Z"].append(pOGRLinearRing->getZ(j));
            }
        }
    }
    return 0;
}

int GetGeometry::Get_MultiPoint(){
    return 0;
}

int GetGeometry::Get_MultiLineString(){
    return 0;
}

int GetGeometry::Get_MultiPolygon(){
    return 0;
}

int GetGeometry::Get_GeometryCollection(){
    return 0;
}
